home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Testing & Debugging / TV-Man Package / With Source Version / Source / TV-Man.Init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-13  |  6.2 KB  |  177 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    TV-Man.Init.c
  4. #
  5. #    Copyright © Apple Computer, Inc. 1989-1990
  6. #    All rights reserved.
  7. #
  8. #    
  9. #    These are the all the functions that are necessary to initalize
  10. #    the application. After these are used they will never be used again.
  11. #    Therefore this segment will be unloaded at the end of its usefullness.
  12. #
  13. #    In order to have an evironment which predictable events happen several definitions
  14. #    must be established. The most critical is in the file architecture. Each functional
  15. #    block will have its own source and header file. The main project file,  in this
  16. #    case TV-Man, will have its header file included with all other files. This will
  17. #    allow for global constants. The utility source file shall contain functions that
  18. #    are general purpose in nature and that can be used by all other functions. These
  19. #    are intended not to be application or major block specific. In order for this to be 
  20. #    accomodated all functions in the utility source file must use only the information
  21. #    that is passed to them or information that can be gleaned from the system via
  22. #    toolbox calls. There will be no header file associated with the utility file as this
  23. #    will destroy the intent of the utilities.
  24. #
  25. #    There are several files which contain information which is global in nature .These
  26. #    file are included in the main project header file. They are: x.Errors.h, x.Ext.h,
  27. #    x.Protos.h, x.Menus.h. The reason for containing them in seperate files is one of
  28. #    convienience and accesability. 
  29. #
  30. #    
  31. #    Revision Log:
  32. #    
  33. #        4-26-91        RGK        Creation
  34. #
  35. #
  36. ------------------------------------------------------------------------------*/
  37.  
  38.  
  39. /*    This is the list of "local" include files    */
  40.  
  41. #include "TV-Man.h"
  42. #include "TV-Man.Video.h"
  43. #include "TV-Man.Sound.h"
  44.  
  45.  
  46.  
  47. #pragma segment Initialize        /*    set this files code segment    */
  48.  
  49.  
  50.  
  51. /*    Set up the whole world, including global variables, Toolbox managers,
  52.     and menus. Also create the one application window at this time.    Because
  53.     TV-Man has only one window and it is only disposed when the application
  54.     quits, we will allocate its space here, before anything that might be a locked
  55.     relocatable object gets into the heap. This way, we can force the storage to be
  56.     in the lowest memory available in the heap. Window storage can differ widely
  57.     amongst applications depending on how many windows are created and disposed. */
  58.  
  59. void Initialize()
  60. {
  61.     Handle        menuBar;
  62.     WindowPtr    window;
  63.     long        total, contig;
  64.     EventRecord event;
  65.     short        count;
  66.     Rect        maxrect;
  67.     short        wtop, wleft, wright, wbottom;
  68.  
  69.     gInBackground = false;
  70.  
  71.     InitGraf((Ptr) &qd.thePort);
  72.     InitFonts();
  73.     InitWindows();
  74.     InitMenus();
  75.     TEInit();
  76.     InitDialogs(nil);
  77.     InitCursor();
  78.  
  79.  
  80.     
  81. /*    This next bit of code is necessary to allow the default button of our
  82.     alert be outlined. Call EventAvail so that we don't lose some important
  83.     events. */
  84.      
  85.     for (count = 1; count <= 3; count++)
  86.         EventAvail(everyEvent, &event);
  87.     
  88.     
  89.     
  90.     
  91. /*    Ignore the error returned from SysEnvirons; even if an error occurred,
  92.     the SysEnvirons glue will fill in the SysEnvRec. You can save a redundant
  93.     call to SysEnvirons by calling it after initializing AppleTalk. */
  94.      
  95.     SysEnvirons(kSysEnvironsVersion, &gMac);
  96.     
  97.     
  98.     
  99.     
  100. /* Make sure that the machine has at least 128K ROMs. If it doesn't, exit. */
  101.     
  102.     if (gMac.machineType < 0) Error(eMajor, eMajorRoms);
  103.     
  104.         
  105.     
  106. /*    Move TrapAvailable call to after SysEnvirons so that we can tell
  107.     in TrapAvailable if a tool trap value is out of range. */
  108.         
  109.     gHasWaitNextEvent = TrapAvailable(_WaitNextEvent, ToolTrap);
  110.  
  111.  
  112.  
  113. /*    Check the size of the application heap against a value that has been determined is
  114.     the smallest heap this application can reasonably work in. This number should be
  115.     derived by examining the size of the heap that is actually provided by MultiFinder
  116.     when the minimum size requested is used. The derivation of the minimum size requested
  117.     from MultiFinder is described in TV-Man.h. The check should be made because the
  118.     preferred size can end up being set smaller than the minimum size by the user.
  119.     This extra check acts to insure that your TV-Man is starting from a solid
  120.     memory foundation. */
  121.      
  122.     if ((long) GetApplLimit() - (long) ApplicZone() < kMinHeap) Error(eMajor, eMajorHeap);
  123.     
  124. /*    Now, make sure that enough memory is free for your TV-Man to run. To check
  125.     for this, call PurgeSpace and compare the result with a value that you have
  126.     determined is the minimum amount of free memory TV-Man needs at initialization. */
  127.     
  128.     PurgeSpace(&total, &contig);
  129.     if (total < kMinSpace) Error(eMajor, eMajorRam);    /* error if to little RAM */
  130.  
  131.  
  132. /*    make as large a window as the target maching can handle    */
  133.  
  134.     window = (WindowPtr) NewPtr(sizeof(WindowRecord));
  135.     if ((window == nil) || (ResError() != noErr))    /*    check for a resource error    */
  136.         Error(eMajor, eMajorWindow);            /*    display major error alert box
  137.                                                         and dont come back    */
  138.     
  139.     
  140. /*    make a rectangle as large as possible but leave up the menu bar. The extra calculations
  141.     in the SetRect are an effort to create a window with an even width and height. The variable
  142.     setting of the wXXXX stuff is just for readability. Often I will burn the variable area 
  143.     in favor of using it instead of a compound (ie. looong) statement.    */
  144.     
  145.     wtop = qd.screenBits.bounds.top;
  146.     wleft = qd.screenBits.bounds.left;
  147.     wright = qd.screenBits.bounds.right;
  148.     wbottom = qd.screenBits.bounds.bottom;
  149.  
  150.     SetRect(&maxrect, wleft, wtop + 20,
  151.                     ((((wright - wleft) +1) /2) *2) +wleft,    /*    set up the right side    */
  152.                     ((((wbottom - wtop) +1) /2) *2) +wtop);    /*    set up the left side    */
  153.                     
  154.                     
  155. /*    Now make our only window out of the rectangle    */
  156.  
  157.     window = NewCWindow( (Ptr)window, &maxrect,"TV-Man",
  158.                         true, 2,(WindowPtr) -1, false, nil);
  159.                         
  160.     
  161.  
  162. /*    set up the menus    */
  163.  
  164.     menuBar = GetNewMBar(rMenu);                    /*    read menus into menu bar    */
  165.     if ((menuBar == nil) || (ResError() != noErr))    /*    check for a resource error    */
  166.         Error(eMajor, eMajorMenu);                /*    display major error alert box
  167.                                                         and dont come back    */
  168.     SetMenuBar(menuBar);                            /*    install menus    */
  169.     DisposHandle(menuBar);
  170.     AddResMenu(GetMHandle(mApple), 'DRVR');            /*    add DA names to Apple menu    */
  171.     DrawMenuBar();
  172.     
  173.     gVideoPattern = iTestPattern;                    /*    initalize the video parameters    */
  174. } /*Initialize*/
  175.  
  176.  
  177.